//
//  RootViewController.m
//  ViewAnimationTest
//
//  Created by 성주 이 on 5/17/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ZinMainViewController.h"
#import "MyTreeViewCell.h"
#import "TreeView.h"
#import "SmartSearchView.h"
#import "SampleBookViewWallpaper.h"
#import "SampleBookViewFlooring.h"
#import "SmartCounselMainView.h"
#import "DatabaseManager.h"
#import "Util.h"
#import "MbochureMainView.h"
#import "MatchingViewController.h"
//@interface ZinMainViewController ()
//
//@end

@implementation ZinMainViewController

@synthesize _leftMenuBar;
@synthesize _mainStage;
@synthesize _rightMenuBar;
@synthesize CurrentView;
@synthesize secDepthView;
@synthesize leftMenuScroll;
@synthesize rightMenuScroll;
@synthesize leftMenuButtonList;
@synthesize rightMenuButtonList;

@synthesize rootButtonImg; 
@synthesize subButtonLastImg;
@synthesize rootButtonPressedImg;
@synthesize secDepthViewWallpaper;



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
       
    }
    return self;
}

#define SIZE_WIDE 204.0f
#define SIZE_NARROW  50.0f
#define SIZE_TOPBAR 60.0f
#define SAMPLE_LIST_HIGHT 61.0f
#define LEFT_SAMPLEBOOKLIST_TAG 100
#define RIGHT_SAMPLEBOOKLIST_TAG 200

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    _isExpanded = NO;
    
    [self.view setFrame:CGRectMake(0, 0, 1024, 768)];
//    [self.view setBackgroundColor:[UIColor blackColor]];
    UIImage* BGImage = [UIImage imageNamed:@"bg_main"];
    UIImageView* bgMain = [[UIImageView alloc] initWithImage:BGImage];
    UIImageView* BackgroundImg  = [Util cropImage: @"bg_main" targetX:0 targetY:0 targetWidth:SIZE_WIDE targetHeight:718 resultX:0 resultY:0 resultWidth:SIZE_WIDE resultHeight:718];
    [self.view addSubview:bgMain];

    // 왼쪽 메뉴
    self._leftMenuBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SIZE_WIDE, 718)];
//    [BackgroundImg setFrame:CGRectMake(0, 0, SIZE_WIDE, 718)];
    [self._leftMenuBar addSubview:BackgroundImg];
    [self.view addSubview:self._leftMenuBar];
    
    UIImageView* BackgroundImgRight = [Util cropImage: @"bg_main" targetX:1024-SIZE_WIDE targetY:0 targetWidth:SIZE_WIDE targetHeight:718 resultX:0 resultY:0 resultWidth:SIZE_WIDE resultHeight:718];

    // 오른쪽 메뉴
    self._rightMenuBar = [[UIView alloc] initWithFrame:CGRectMake(1024-SIZE_WIDE, 0, SIZE_WIDE, 718)];
    [self._rightMenuBar addSubview:BackgroundImgRight];
    [self.view addSubview:self._rightMenuBar];
   
    UIImageView* BackgroundImgCenter = [Util cropImage: @"bg_main" targetX:SIZE_WIDE targetY:0 targetWidth:1024-SIZE_WIDE-SIZE_WIDE targetHeight:718 resultX:0 resultY:0 resultWidth:1024-SIZE_WIDE-SIZE_WIDE resultHeight:718];
    
    // 가운데 메인스테이지
    self._mainStage = [[UIView alloc] initWithFrame:CGRectMake(SIZE_WIDE, 0,1024-SIZE_WIDE-SIZE_WIDE, 718)];
//    [self._mainStage setBackgroundColor:[UIColor yellowColor]];
    [self._mainStage addSubview:BackgroundImgCenter];
    [self.view addSubview:self._mainStage];
    
    CurrentView = _mainStage;
    CurrentViewIndex = 0;
    
    [self mainStageView];
    
//    tv = [[TreeView alloc] init];
//    tv.trdelegate = self;
//    [tv.view setFrame:CGRectMake(10*2, 110, 188-18, 615-99)];
//
//    [_rightMenuBar addSubview:tv.view];
    
    sampleBookView = [[SampleBookViewWallpaper alloc] init];
    sampleBookViewFlooring = [[SampleBookViewFlooring alloc] init];
    
    rootButtonImg = [UIImage imageNamed:@"bg_lnb_m"];
    subButtonLastImg = [UIImage imageNamed:@"bg_lnb_b"];
    rootButtonPressedImg = [UIImage imageNamed:@"btn_rollOver"];
    
    // 왼쪽 메뉴 항목
    [self leftMenuView];
    
    [self rightMenuView];
    [self bottomMenuView];
}
-(void)leftMenuView
{
    
    UIImage* leftMenuTitleImage = [UIImage imageNamed:@"tit_lnb"];
    UIImageView* leftMenuTitleImageView  = [[UIImageView alloc] initWithImage:leftMenuTitleImage];
    [leftMenuTitleImageView setFrame:CGRectMake(11, 11, 188, 99)];
    [self._leftMenuBar addSubview:leftMenuTitleImageView];
    
    UIImageView* bgLeftMenuScroll = [Util tileImage:@"bg_lnb_m" resultX:0 resultY:0 resultWidth:188 resultHeight:530];
    leftMenuScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(11, 110, 188, 530)];
    [leftMenuScroll setContentSize:CGSizeMake(188, 50*10 + SAMPLE_LIST_HIGHT)];
    [leftMenuScroll addSubview:bgLeftMenuScroll];
    [self._leftMenuBar addSubview:leftMenuScroll];
    
    [self MakeLeftMenuButton];
    
//    UIImageView* blankList = [[UIImageView alloc] initWithImage:rootButtonImg];
//    [blankList setFrame:CGRectMake(0, i*50, 188, 51)];
//    [leftMenuScroll addSubview:blankList];

        
    
//    UIImage* SampleBookButtonImg = [UIImage imageNamed:@"bg_lnb_b"];
//    UIButton* SampleBookListbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, 540, 188, 61)];
//    [SampleBookListbutton setBackgroundImage:SampleBookButtonImg forState:UIControlStateNormal];
//    [SampleBookListbutton setTag:LEFT_SAMPLEBOOKLIST_TAG];
//    [SampleBookListbutton addTarget:self action:@selector(SampleBookListbuttonPressed:) forControlEvents:UIControlEventTouchUpInside];
//    [SampleBookListbutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [SampleBookListbutton setTitle: @"샘플북 리스트" forState:UIControlStateNormal];
//    [leftMenuScroll addSubview:SampleBookListbutton];

}
-(void)MakeLeftMenuButton
{
    NSMutableArray* leftRootList = [[NSMutableArray alloc] init ];
    [leftRootList addObject:@"프리미엄벽지"];
    [leftRootList addObject:@"실크벽지"];
    [leftRootList addObject:@"합지벽지"];
    [leftRootList addObject:@"벽타일"];
    
       
    for (int i = 0; i < [leftRootList count]; i++) 
    {
      
        UIFont *font;
        font = [UIFont boldSystemFontOfSize:16];
        UIButton *listRootbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, i*50, 188, 50)];
        [listRootbutton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
        [listRootbutton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
        [listRootbutton addTarget:self action:@selector(listRootbuttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [listRootbutton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
        [listRootbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [listRootbutton setTitle: [leftRootList objectAtIndex:i] forState:UIControlStateNormal];
        [listRootbutton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [listRootbutton setTitleEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
        [listRootbutton setTag:i];
        listRootbutton.titleLabel.font = font;
        [leftMenuScroll addSubview:listRootbutton];
        
    }
       
}
-(void)ClearLeftScrollView
{
    NSArray *subviews = leftMenuScroll.subviews;
    for(int i =0;i<[subviews count];i++)
    {
        [[subviews objectAtIndex:i] removeFromSuperview];
    }
}
-(void)listRootbuttonPressed:(id)sender
{
    nIndexRootWallpaper = -1;
    UIImageView* bgLeftMenuScroll = [Util tileImage:@"bg_lnb_m" resultX:0 resultY:0 resultWidth:188 resultHeight:530];
    self.secDepthViewWallpaper = [[UIView alloc]initWithFrame:CGRectMake(-188, 110 ,0, 530)];
    [self.secDepthViewWallpaper addSubview:bgLeftMenuScroll];
    [self.view addSubview:self.secDepthViewWallpaper];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [self.secDepthViewWallpaper setFrame:CGRectMake(11,110,188,530)];
    [UIView commitAnimations];

    switch ([sender tag]) {
        case 0:
        {
            nIndexRootWallpaper = 0;
            NSMutableArray* secWallpaperList = [[NSMutableArray alloc] init ];
            [secWallpaperList addObject:@"지아벽지"];
            [secWallpaperList addObject:@"베라왕"];
            [secWallpaperList addObject:@"애냐라킨"];
            [secWallpaperList addObject:@"뮤럴벽지"];
            [self makesubDepthWallpaperButton:secWallpaperList];
        }
            break;
        case 1:
        {
            nIndexRootWallpaper = 1;
            NSMutableArray* secWallpaperList = [[NSMutableArray alloc] init ];
            [secWallpaperList addObject:@"공기를 살리는 벽지"];
            [secWallpaperList addObject:@"아이비리그"];
            [secWallpaperList addObject:@"실크NB"];
            [secWallpaperList addObject:@"실크테라피"];
            [secWallpaperList addObject:@"방염벽지"];
            [self makesubDepthWallpaperButton:secWallpaperList];
        }
            break;
        case 2:
        {
           nIndexRootWallpaper = 2;
            NSMutableArray* secWallpaperList = [[NSMutableArray alloc] init ];
            [secWallpaperList addObject:@"휘앙새"];
            [self makesubDepthWallpaperButton:secWallpaperList];
        }
            break;
        case 3:
        {
           nIndexRootWallpaper = 3;
            NSMutableArray* secWallpaperList = [[NSMutableArray alloc] init ];
            [secWallpaperList addObject:@"공기를 살리는 숨타일"];
            [self makesubDepthWallpaperButton:secWallpaperList];

        }
            break;
            
        default:
            break;
            
    }
}

-(void)makesubDepthWallpaperButton:(NSMutableArray*)list 
{
    UIButton* TopButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [TopButton setFrame: CGRectMake(0, 0, 188, 50)];
    [TopButton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
    [TopButton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
    [TopButton addTarget:self action:@selector(wallpaperTopButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [TopButton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
    [TopButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [TopButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [TopButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
    [TopButton setTitle:[Util findWallpaperRootCategoryName: nIndexRootWallpaper ] forState:UIControlStateNormal];
    [self.secDepthViewWallpaper addSubview:TopButton];
    
    for(int i = 0; i < [list count];i++)
    {
        UIFont *font;
        font = [UIFont boldSystemFontOfSize:14];
        UIButton *listLastDepthButton;
        listLastDepthButton = [[UIButton alloc] initWithFrame:CGRectMake(0, i*50+50, 188, 50)];
        [listLastDepthButton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
        [listLastDepthButton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
        [listLastDepthButton addTarget:self action:@selector(leftlistLastDepthButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [listLastDepthButton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
        [listLastDepthButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [listLastDepthButton setTitle: [list objectAtIndex:i] forState:UIControlStateNormal];
        [listLastDepthButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [listLastDepthButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
        [listLastDepthButton setTag:i];
        listLastDepthButton.titleLabel.font = font;
        [secDepthViewWallpaper addSubview:listLastDepthButton];
        
    }
}
-(void)wallpaperTopButtonPressed:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    [secDepthViewWallpaper setFrame:CGRectMake(-188,110,0, 530)];
    [UIView commitAnimations];

    
}
-(void)leftlistLastDepthButtonPressed:(id)sender
{
    int nCategoryIndex;
    nCategoryIndex = [Util findCategory: nIndexRootWallpaper sub:[sender tag]];
    [self leftTreeViewSelect:nCategoryIndex haschilden:NO];
    
    
    
}

-(void)rightMenuView
{
    UIImageView* bgRightMenuScroll = [Util tileImage:@"bg_lnb_m" resultX:0 resultY:0 resultWidth:188 resultHeight:530];
    rightMenuScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(11, 110, 188, 530)];
    [rightMenuScroll setContentSize:CGSizeMake(188, 50*10 + SAMPLE_LIST_HIGHT)];
    [rightMenuScroll addSubview:bgRightMenuScroll];
    [self._rightMenuBar addSubview:rightMenuScroll];
    
    
    UIImage* rightMenuTitleImage = [UIImage imageNamed:@"tit_rnb"];
    UIImageView* rightMenuTitleImageView  = [[UIImageView alloc] initWithImage:rightMenuTitleImage];
    [rightMenuTitleImageView setFrame:CGRectMake(11, 11, 188, 99)];
    [self._rightMenuBar addSubview:rightMenuTitleImageView];
    
//    UIImage* homeFloorImage = [UIImage imageNamed:rootButtonImg];
    UIImageView* homeFloorImageView  = [[UIImageView alloc] initWithImage:rootButtonImg];
    [homeFloorImageView setFrame:CGRectMake(0, 0, 188, 50)];
    [rightMenuScroll addSubview:homeFloorImageView];
    
    UILabel* homeFloorTitlelb = [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 188, 30)];
    [homeFloorTitlelb setBackgroundColor:[UIColor clearColor]];
    [homeFloorTitlelb setFont:[UIFont boldSystemFontOfSize:18]];
    [homeFloorTitlelb setText:@"주택용 바닥재"];
    [homeFloorImageView addSubview:homeFloorTitlelb];
    
//    UIImage* storeFloorImage = [UIImage imageNamed:rootButtonImg];
    UIImageView* storeFloorImageView  = [[UIImageView alloc] initWithImage:rootButtonImg];
    [storeFloorImageView setFrame:CGRectMake(0, 212, 188, 50)];
    [rightMenuScroll addSubview:storeFloorImageView];
    
    UILabel* storeFloorTitlelb = [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 188, 30)];
    [storeFloorTitlelb setBackgroundColor:[UIColor clearColor]];
    [storeFloorTitlelb setFont:[UIFont boldSystemFontOfSize:18]];
    [storeFloorTitlelb setText:@"상업용 바닥재"];
    [storeFloorImageView addSubview:storeFloorTitlelb];

    [rightMenuScroll setContentSize:CGSizeMake(188, 50*10 + SAMPLE_LIST_HIGHT)];
    
    [self MakeRightMenuButton:YES];
    [self MakeRightMenuButton:NO];
    
    UIImageView* storeFloorImageLastView  = [[UIImageView alloc] initWithImage:subButtonLastImg];
    [storeFloorImageLastView setFrame:CGRectMake(0, 463, 188, 61)];
    [rightMenuScroll addSubview:storeFloorImageLastView];
    
}

-(void)MakeRightMenuButton:(BOOL)homeORStore
{
           
    if(homeORStore)
    {
        NSMutableArray* subHomeFloor = [[NSMutableArray alloc] init];
        [subHomeFloor addObject:@"마루"];
        [subHomeFloor addObject:@"시트"];
        [subHomeFloor addObject:@"타일"];
        for (int i = 0; i < [subHomeFloor count]; i++) 
        {
            UIFont *font;
            font = [UIFont boldSystemFontOfSize:16];
            UIButton *listRootbutton;
            if(i == [subHomeFloor count] -1)
            {
                listRootbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, i*50+50, 188, 61)];
                [listRootbutton setBackgroundImage:subButtonLastImg forState:UIControlStateNormal];
                [listRootbutton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
                [listRootbutton setTitleEdgeInsets:UIEdgeInsetsMake(-10, 50, 0, 0)];
            }
            else 
            {
                listRootbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, i*50+50, 188, 50)];
                [listRootbutton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
                [listRootbutton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
                [listRootbutton setTitleEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
            }
        
           
            [listRootbutton addTarget:self action:@selector(rightListSubButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
            [listRootbutton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
            [listRootbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
            [listRootbutton setTitle: [subHomeFloor objectAtIndex:i] forState:UIControlStateNormal];
            [listRootbutton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
            
            [listRootbutton setTag:i];
            listRootbutton.titleLabel.font = font;
            [rightMenuScroll addSubview:listRootbutton];
        }
    }
    else 
    {
        NSMutableArray* subHomeFloor = [[NSMutableArray alloc] init];
        [subHomeFloor addObject:@"타일"];
        [subHomeFloor addObject:@"시트"];
        [subHomeFloor addObject:@"카펫타일"];
        [subHomeFloor addObject:@"스톤타일"];
        for (int i = 0; i < [subHomeFloor count]; i++) 
        {
            UIFont *font;
            font = [UIFont boldSystemFontOfSize:16];
            UIButton *listRootbutton;
            listRootbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, i*50+262, 188, 50)];
            [listRootbutton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
            [listRootbutton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
            [listRootbutton addTarget:self action:@selector(rightListSubButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
            [listRootbutton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
            [listRootbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
            [listRootbutton setTitle: [subHomeFloor objectAtIndex:i] forState:UIControlStateNormal];
            [listRootbutton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
            [listRootbutton setTitleEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
            [listRootbutton setTag:i+10];
            listRootbutton.titleLabel.font = font;
            [rightMenuScroll addSubview:listRootbutton];
        }

    }
    
}


-(void)rightListSubButtonPressed:(id)sender
{
    [self rightListButtonClickSubView:[sender tag]];
//    [self TreeViewSelect:[sender tag] haschilden:NO];
    
}
-(void)rightListButtonClickSubView:(int)index
{
    nIndexRoot = -1;
    UIImageView* bgRightMenuScroll = [Util tileImage:@"bg_lnb_m" resultX:0 resultY:0 resultWidth:188 resultHeight:530];
    self.secDepthView = [[UIView alloc]initWithFrame:CGRectMake(1024, 110 ,0, 530)];
    [self.secDepthView addSubview:bgRightMenuScroll];
    UIScrollView* secDepthScroll = [[UIScrollView alloc] init];
    [secDepthScroll setFrame:CGRectMake(0, 0, 188, 530)];
    [secDepthScroll setBackgroundColor:[UIColor clearColor]];
    [self.secDepthView addSubview:secDepthScroll];
    [self.view addSubview:self.secDepthView];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [self.secDepthView setFrame:CGRectMake(1024-192,110,188,530)];
    [UIView commitAnimations];
    NSMutableArray* itemList = [[NSMutableArray alloc] init];
    switch (index) {
        case 0:
        {
            nIndexRoot = 0;
            
            [itemList addObject:@"지아마루 - 프레스티지"];
            [itemList addObject:@"지아마루 - 7"];
            [itemList addObject:@"원목마루"];
            [itemList addObject:@"녹차마루"];
            [itemList addObject:@"강그린마루"];
            [itemList addObject:@"포르테마루 - 광폭"];
            [itemList addObject:@"포르테마루 - 소폭"];
            
        }   
            break;
        case 1:
        {
            nIndexRoot = 1;
            [itemList addObject:@"소리잠"];
            [itemList addObject:@"휴앤미"];
            [itemList addObject:@"네이쳐라이프"];
            [itemList addObject:@"자연애2.5"];
            [itemList addObject:@"자연애2.2"];
            [itemList addObject:@"자연애1.8"];
            [itemList addObject:@"뉴청맥1.8"];
        }   
            break;
        case 2:
        {
            nIndexRoot = 2;
            [itemList addObject:@"하우스"];
        }   
            break;
        case 10:
        {
            nIndexRoot = 3;
            [itemList addObject:@"데코타일 - 파인.5"];
            [itemList addObject:@"데코타일 - 갤러리"];
            [itemList addObject:@"데코타일 - 에코노"];
            [itemList addObject:@"하우스 이지"];
            [itemList addObject:@"VIP타일-VIP마블/포스트"];
            [itemList addObject:@"VIP타일-VIP인레이드"];
            [itemList addObject:@"VCT타일-갤런트"];
            [itemList addObject:@"VCT타일-GR"];
            [itemList addObject:@"VCT타일-디럭스"];
            [itemList addObject:@"기능성타일-VIP전도성"];
            [itemList addObject:@"기능성타일-OA"];
        }   
            break;
        case 11:
        {
            nIndexRoot = 4;
            [itemList addObject:@"우븐"];
            [itemList addObject:@"지아플로어 호모젠"];
            [itemList addObject:@"엘스트롱 유나이트"];
            [itemList addObject:@"엘스트롱 클레버"];
            [itemList addObject:@"엘스트롱 노블아트"];
            [itemList addObject:@"네이쳐라이프"];
            [itemList addObject:@"와이드"];
            [itemList addObject:@"EQ플로어"];
            [itemList addObject:@"렉스코트"];
            [itemList addObject:@"SD메탈/트랜스"];

        }   
            break;
        case 12:
        {
            nIndexRoot = 5;
            [itemList addObject:@"Style"];
            [itemList addObject:@"L1000"];
            [itemList addObject:@"L9300"];
            [itemList addObject:@"L9600"];
            [itemList addObject:@"L9700"];
            [itemList addObject:@"L3300"];
            [itemList addObject:@"L7000"];

        }   
            break;
        case 13:
        {
            nIndexRoot = 6;
            [itemList addObject:@"마블"];
            [itemList addObject:@"폴리싱"];
        }   
            break;
            
        default:
            break;
    }
    [secDepthScroll setContentSize:CGSizeMake(188, [itemList count]*50+50)];
     [self makesubDepthButton:itemList scroll:secDepthScroll];
}
-(void)TopButtonPressed:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    [secDepthView setFrame:CGRectMake(1024,110,0, 530)];
    [UIView commitAnimations];
}

-(void)makesubDepthButton:(NSMutableArray*)list  scroll:(UIScrollView*)scrollView
{
    UIButton* TopButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [TopButton setFrame: CGRectMake(0, 0, 188, 50)];
    [TopButton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
    [TopButton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
    [TopButton addTarget:self action:@selector(TopButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [TopButton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
    [TopButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [TopButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [TopButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
    [TopButton setTitle:[Util findFloorRootCategoryName: nIndexRoot ] forState:UIControlStateNormal];
    [scrollView addSubview:TopButton];

    for(int i = 0; i < [list count];i++)
    {
        UIFont *font;
        font = [UIFont boldSystemFontOfSize:14];
        UIButton *listLastDepthButton;
        listLastDepthButton = [[UIButton alloc] initWithFrame:CGRectMake(0, i*50+50, 188, 50)];
        [listLastDepthButton setBackgroundImage:rootButtonImg forState:UIControlStateNormal];
        [listLastDepthButton setBackgroundImage:rootButtonPressedImg forState:UIControlStateHighlighted];
        [listLastDepthButton addTarget:self action:@selector(rightlistLastDepthButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [listLastDepthButton setTitleColor:[UIColor colorWithRed:0.29f green:0.29f blue:0.29f alpha:1.0f] forState:UIControlStateNormal];
        [listLastDepthButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [listLastDepthButton setTitle: [list objectAtIndex:i] forState:UIControlStateNormal];
        [listLastDepthButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [listLastDepthButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
        [listLastDepthButton setTag:i];
        listLastDepthButton.titleLabel.font = font;
        [scrollView addSubview:listLastDepthButton];
        
    }
}
-(void)rightlistLastDepthButtonPressed:(id)sender
{
    nIndexSub = [sender tag];
    categoryValue = [Util findCategory:nIndexRoot sub:nIndexSub];
    [self TreeViewSelect: nIndexRoot haschilden:NO];
}
-(void)bottomMenuView
{
    UIButton* zinButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [zinButton setFrame:CGRectMake(0,718 ,213, 50)];
    UIImage* zinLogoImg = [UIImage imageNamed:@"h1_logo"];
    [zinButton setImage:zinLogoImg forState:UIControlStateNormal];
    [zinButton addTarget:self action:@selector(zinButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zinButton];
    
    UIButton* zinSampleBookButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [zinSampleBookButton setFrame:CGRectMake(213,718 ,199, 50)];
    UIImage* zinSampleBookButtonImg = [UIImage imageNamed:@"gnb_01"];
    [zinSampleBookButton setImage:zinSampleBookButtonImg forState:UIControlStateNormal];
    UIImage* zinSampleBookButtonPressedImg = [UIImage imageNamed:@"gnb_01_on"];
    [zinSampleBookButton setImage:zinSampleBookButtonPressedImg forState:UIControlStateHighlighted];
    [zinSampleBookButton addTarget:self action:@selector(zinSampleBookButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zinSampleBookButton];
    
    UIButton* smartCounselButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [smartCounselButton setFrame:CGRectMake(412,718 ,199, 50)];
    UIImage* smartCounselButtonImg = [UIImage imageNamed:@"gnb_02"];
    [smartCounselButton setImage:smartCounselButtonImg forState:UIControlStateNormal];
    UIImage* smartCounselButtonPressedImg = [UIImage imageNamed:@"gnb_02"];
    [smartCounselButton setImage:smartCounselButtonPressedImg forState:UIControlStateHighlighted];
    
    [smartCounselButton addTarget:self action:@selector(smartCounselButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:smartCounselButton];
    
    UIButton* mBrochureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mBrochureButton setFrame:CGRectMake(611,718 ,201, 50)];
    UIImage* mBrochureButtonImg = [UIImage imageNamed:@"gnb_03"];
    [mBrochureButton setImage:mBrochureButtonImg forState:UIControlStateNormal];
    UIImage* mBrochureButtonPressedImg = [UIImage imageNamed:@"gnb_03"];
    [mBrochureButton setImage:mBrochureButtonPressedImg forState:UIControlStateHighlighted];
    [mBrochureButton addTarget:self action:@selector(mBrochureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:mBrochureButton];
    
    UIButton* matchingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [matchingButton setFrame:CGRectMake(812,718 ,53, 50)];
    UIImage* matchingButtonImg = [UIImage imageNamed:@"btn_option_01"];
    [matchingButton setImage:matchingButtonImg forState:UIControlStateNormal];
    UIImage* matchingButtonPressedImg = [UIImage imageNamed:@"btn_option_01"];
    [matchingButton setImage:matchingButtonPressedImg forState:UIControlStateHighlighted];
    [matchingButton addTarget:self action:@selector(matchingButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:matchingButton];
    
    UIButton* calcButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [calcButton setFrame:CGRectMake(865,718 ,53, 50)];
    UIImage* calcButtonImg = [UIImage imageNamed:@"btn_option_02"];
    [calcButton setImage:calcButtonImg forState:UIControlStateNormal];
    UIImage* calcButtonPressedImg = [UIImage imageNamed:@"btn_option_02"];
    [calcButton setImage:calcButtonPressedImg forState:UIControlStateHighlighted];
    [calcButton addTarget:self action:@selector(calcButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:calcButton];
    
    UIButton* aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aboutButton setFrame:CGRectMake(918,718 ,53, 50)];
    UIImage* aboutButtonImg = [UIImage imageNamed:@"btn_option_03"];
    [aboutButton setImage:aboutButtonImg forState:UIControlStateNormal];
    UIImage* aboutButtonPressedImg = [UIImage imageNamed:@"btn_option_03"];
    [aboutButton setImage:aboutButtonPressedImg forState:UIControlStateHighlighted];
    [aboutButton addTarget:self action:@selector(aboutButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:aboutButton];
    
    UIButton* settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingButton setFrame:CGRectMake(971,718 ,53, 50)];
    UIImage* settingButtonImg = [UIImage imageNamed:@"btn_option_04"];
    [settingButton setImage:settingButtonImg forState:UIControlStateNormal];
    UIImage* settingButtonPressedImg = [UIImage imageNamed:@"btn_option_04"];
    [settingButton setImage:settingButtonPressedImg forState:UIControlStateHighlighted];
    [settingButton addTarget:self action:@selector(settingButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:settingButton];
}
-(void)matchingButtonPressed:(id)sender
{
    MatchingViewController* abc = [[MatchingViewController alloc] init];
    [self.navigationController pushViewController:abc animated:YES];
}
-(void)calcButtonPressed:(id)sender
{
    
}
-(void)aboutButtonPressed:(id)sender
{
    
}
-(void)settingButtonPressed:(id)sender
{
    
}
-(void)mainStageView
{
    // 메인스테이지 라벨
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(50, SIZE_TOPBAR + 200, 400, 20)];
    [label setText:@"Select a menu"];
    [label setTextAlignment:UITextAlignmentLeft];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setFont:[UIFont systemFontOfSize:20.0f]];
    [self._mainStage addSubview:label];
    
    UIButton* SearchButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [SearchButton setFrame:CGRectMake(400,SIZE_TOPBAR + 500 , 200, 36)];
    [SearchButton setTitle:[NSString stringWithFormat:@"검색결과 제품보기"] forState:UIControlStateNormal];
    [SearchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [SearchButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [SearchButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 45, 5, 5)];
    [SearchButton addTarget:self action:@selector(SearchButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self._mainStage addSubview:SearchButton];
}

-(void)dealloc
{
    [self._leftMenuBar release];
    [self._mainStage release];
    [self._rightMenuBar release];
//    [tv release];
    
    [super dealloc];
}

-(void)zinButtonPressed:(id)sender
{
    [sampleBookView.view removeFromSuperview];
    [sampleBookViewFlooring.view removeFromSuperview];
//    [tv.view removeFromSuperview];
    [sampleBookView release];
    [sampleBookViewFlooring release];
//    [tv release];
    
    
//    [self.view removeFromSuperview];
//    [_mainStage release];
//    [sampleBookView release];
//    [sampleBookViewFlooring release];
    [self viewDidLoad];
//    self._mainStage = [[UIView alloc] initWithFrame:CGRectMake(200, SIZE_TOPBAR,1024-SIZE_WIDE*2, 748)];
//    [self._mainStage setBackgroundColor:[UIColor grayColor]];
//    [self.view addSubview:self._mainStage];
//    [self mainStageView];
//     [tv.view setFrame:CGRectMake(SIZE_WIDE+1024-(SIZE_WIDE*2)+20, SIZE_TOPBAR, SIZE_WIDE-20, 748)];
}
-(void)MatchingButtonPressed:(id)sender
{
    
}

-(void)CalButtonPressed:(id)sender
{
    
}

-(void)SetButtonPressed:(id)sender
{
    
}

-(void)HelpButtonPressed:(id)sender
{
    
}

-(void)zinSampleBookButtonPressed:(id)sender
{
    
}
-(void)smartCounselButtonPressed:(id)sender
{
    SmartCounselMainView* smartCounselMainView = [[SmartCounselMainView alloc] init];
    [self.navigationController pushViewController:smartCounselMainView animated:YES];
    [self release];
    
}
-(void)mBrochureButtonPressed:(id)sender
{
    MbochureMainView* abc = [[MbochureMainView alloc] init];
    [self.navigationController pushViewController:abc animated:YES];
//    [self release];
    
}


#pragma mark - Button Handler
-(void)buttonPressed:(id)sender
{
    // 메인스테이지에 선택된 버튼 타이틀 표시
  //    [self.navigationController pushViewController:sampleBookView animated:YES];
}

-(void)TreeViewSelect:(NSInteger)selectedIndex haschilden:(BOOL)lastElement
{
//    NSLog(@"delegate Come ");
     NSLog(@"%d",selectedIndex);
    if(CurrentViewIndex == 2)
    {
        treeSelectIndex = selectedIndex;
//        if(lastElement)
//        {
//            NSLog(@"%d ",lastElement);
//            [self TreeViewSelectView];
//        }
        return;
    }
    float mainStageWidth = CurrentView.frame.size.width;
    
    [self._mainStage removeFromSuperview];
    [sampleBookView.view removeFromSuperview];
    [sampleBookViewFlooring.view removeFromSuperview];
    
    [sampleBookViewFlooring.view setFrame:CGRectMake(self._leftMenuBar.frame.origin.x + SIZE_WIDE, CurrentView.frame.origin.y, mainStageWidth, CurrentView.frame.size.height)];
//    [sampleBookViewFlooring.view setBackgroundColor:[UIColor yellowColor]];
    [self.view addSubview:sampleBookViewFlooring.view];
    
    CurrentView = sampleBookViewFlooring.view;
    CurrentViewIndex = 2;
       
    UIView* wideMenu;
    UIView* narrowMenu;
    
    wideMenu = self._rightMenuBar;
    narrowMenu = self._leftMenuBar;
    
//    float mainStageWidth = CurrentView.frame.size.width;
    float sizeDiscrepancy = SIZE_WIDE - SIZE_NARROW;
    if(!_isExpanded)
    {
        _isExpanded = YES;
        mainStageWidth = CurrentView.frame.size.width + sizeDiscrepancy;
    }
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    [self._leftMenuBar setFrame:CGRectMake(-(SIZE_WIDE/2), self._leftMenuBar.frame.origin.y, self._leftMenuBar.frame.size.width, self._leftMenuBar.frame.size.height)];
    [self.CurrentView setFrame:CGRectMake((SIZE_WIDE/2), CurrentView.frame.origin.y, CurrentView.frame.size.width , CurrentView.frame.size.height)];
    [self._rightMenuBar setFrame:CGRectMake(1024-SIZE_WIDE, 0, SIZE_WIDE, 718-11)];
    [UIView commitAnimations];
    
//     [tv.view setFrame:CGRectMake(SIZE_WIDE+1024-(SIZE_WIDE*2)+20, 0, SIZE_WIDE-20, 700)];
    
//    CurrentView = sampleBookViewFlooring.view;

    treeSelectIndex = selectedIndex;
//    if(lastElement)
//    {
//        NSLog(@"%d ",lastElement);
//        [self TreeViewSelectView];
//    }
//    [self.view bringSubviewToFront:self._leftMenuBar];
//    [self.view bringSubviewToFront:self._rightMenuBar];
//    [self.view bringSubviewToFront:tv.view];
//    [self.view bringSubviewToFront:self._leftMenuBar];

    
       
}

-(void)leftTreeViewSelect:(NSInteger)selectedIndex haschilden:(BOOL)lastElement
{

    [sampleBookViewFlooring.view removeFromSuperview];
    
    if(CurrentViewIndex == 2)
    {
        [sampleBookView.view setFrame:CGRectMake(204, 11, 1024-204-204/2, 686)];
        [sampleBookView categoryIndexReceive:selectedIndex];
        //        [sampleBookView.view setBackgroundColor:[UIColor blueColor]];
        
        ////////////////////////////
        //이미지 갯수 받아와서 전송해야 함
        //////////////////////////
        [self.view addSubview:sampleBookView.view];
    }
    else 
    {
        [sampleBookView.view setFrame:CGRectMake(204, 11, 1024-204-204/2, 686)];
        [sampleBookView categoryIndexReceive:selectedIndex];

        //        [sampleBookView.view setBackgroundColor:[UIColor blueColor]];
        ////////////////////////////
        //이미지 갯수 받아와서 전송해야 함
        ////////////////////////////
        
        [self.view addSubview:sampleBookView.view];
    }
    CurrentView = sampleBookView.view;
    CurrentViewIndex = 1;
    
    
    // 왼쪽/오른쪽 메뉴영역 크기 조절 애니메이션 부분
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
//    [self._leftMenuBar setFrame:CGRectMake(0, 0, SIZE_WIDE, 718-11)];
    [self.CurrentView setFrame:CGRectMake(204, 11, 1024-204-204/2, 686)];
    [self._rightMenuBar setFrame:CGRectMake(1024-SIZE_WIDE + SIZE_WIDE/2 , self._rightMenuBar.frame.origin.y, SIZE_WIDE, self._rightMenuBar.frame.size.height)];
    
//    [self.view bringSubviewToFront:self._rightMenuBar];
//    [self.view bringSubviewToFront:self._leftMenuBar];
    
    [UIView commitAnimations];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

-(void)SearchButtonPressed:(id)sender
{
    SmartSearchView * smartSearchView = [[SmartSearchView alloc] init];
    
    [self.navigationController pushViewController:smartSearchView animated:YES];
}

@end
